package com.mt.api.modules.manager.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mt.api.modules.domain.BossPrinter;
import com.mt.api.modules.domain.bo.PrinterUpdateBo;
import com.mt.api.modules.manager.IBossPrinterManager;
import com.mt.api.modules.mapper.BossPrinterMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;


/**
 * @Author: plover
 * @Date: 2022-02-12
 * @Description:
 */
@Component
public class BossPrinterManagerImpl extends ServiceImpl<BossPrinterMapper, BossPrinter> implements IBossPrinterManager {


    @Override
    public BossPrinter getByDeviceId(String deviceId) {
        LambdaQueryWrapper<BossPrinter> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(BossPrinter::getDeviceId, deviceId)
                .last("limit 1")
                .orderByDesc(BossPrinter::getId);
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public BossPrinter getBossPrinterByBossId(Integer bossId, String osType, String osVersion) {
        LambdaQueryWrapper<BossPrinter> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(BossPrinter::getBossId, bossId)
                .eq(BossPrinter::getOsType, osType)
                .eq(BossPrinter::getOsVersion, osVersion)
                .last("limit 1")
                .orderByDesc(BossPrinter::getId);
        return baseMapper.selectOne(wrapper);
    }


    @Override
    public BossPrinter getByParam(PrinterUpdateBo bo) {
        LambdaQueryWrapper<BossPrinter> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(BossPrinter::getDeviceId, bo.getDeviceId())
                .eq(StringUtils.isNotEmpty(bo.getOsType()), BossPrinter::getOsType, bo.getOsType())
                .eq(StringUtils.isNotEmpty(bo.getOsVersion()), BossPrinter::getOsVersion, bo.getOsVersion())
                .last("limit 1")
                .orderByDesc(BossPrinter::getId);
        return baseMapper.selectOne(wrapper);
    }

}
